package Railroad.Communication;

import java.util.ArrayList;
import java.util.List;

public class CommData {
    private final List<Byte> data = new ArrayList<>();
    private byte currentByte = 0;
    
    
    public CommData() {
    }

    public CommData(byte[] from) {
        for (byte d : from)
            data.add(d);
    }
    
    public CommData put(byte value) {
        data.add(value);
        return this;
    }
    
    public void clear() {
        data.clear();
    }
    
    public int size() {
        return data.size();
    }
    
    public final byte[] toArray() {
         byte[] arr = new byte[data.size()];
         for (int i = 0; i < arr.length; i++)
             arr[i] = data.get(i);
         return arr;
    }
    
    public byte get() {
        return data.get(currentByte++);
    }
}
